package arcomage;

import java.util.*; //for Lists, shuffle etc

public class AmDeck
{
    private List<AmCard> drawPile;
    private List<AmCard> discardPile;
    private static int initialDeckSize;
    /** constructor initialises a full deck into the draw pile, and an empty
     *  discard pile.
     */
    public AmDeck()
    {
        drawPile = new ArrayList<AmCard>();
        discardPile = new ArrayList<AmCard>();
        initialDeckSize = 0;
    }
    /** Retrieves the next AmCard from the draw pile. */
    public AmCard drawCard()
    {
        if (numCardsLeftToDraw() == 0)
        {
            returnDiscardedToDraw();
        }
        return drawPile.remove(0);
    }
    /** Retrieves a List of the next numToDrawIn cards from the draw pile. */
    public List<AmCard> drawCards(int numToDrawIn)
    {
        List<AmCard> retList = new ArrayList<AmCard>();
        for (int i = 0; i < numToDrawIn; i++)
        {
            retList.add(drawCard());
        }
        return retList;
    }
    /** Return a card to the discard pile */
    public void discardCard(AmCard cardIn)
    {
        discardPile.add(cardIn);
    }
    /** Returns a List cards to the discard pile. */
    public void discardCards(List<AmCard> cardsIn)
    {
        while (!cardsIn.isEmpty())
        {
            discardPile.add(cardsIn.remove(0));
        }
    }
    /** Returns the number of cards in the draw pile */
    public int numCardsLeftToDraw()
    {
        return drawPile.size();
    }
    /** Returns the number of cards in the discard pile */
    public int numCardsDiscarded()
    {
        return discardPile.size();
    }
    /** Returns the number of cards currently in play (i.e. not in the discard
     *  or draw pile)
     */
    public int numCardsInPlay()
    {
        return (initialDeckSize - numCardsLeftToDraw() - numCardsDiscarded());
    }
    /** Shuffles the discard pile, then adds it to the draw pile again.
     *  @return returns the new size of the draw pile
     */
    public int returnDiscardedToDraw()
    {
        Collections.shuffle(discardPile);
        while (!discardPile.isEmpty())
        {
            drawPile.add(discardPile.remove(0));
        }
        return numCardsLeftToDraw();
    }
}
